unit  GR32_FloatMap;

interface  
{$I GR32.inc}  
uses  
  {$IFDEF FPC}  
  Controls, Graphics,  
  {$IFDEF Windows}
  Windows,  
  {$ENDIF}  
  {$ELSE}  
  Windows, Controls, Graphics,  
  {$ENDIF}  
  Classes, SysUtils, GR32, GR32_VectorMaps;  
type  
  TFloatMap = class(TCustomMap)  
  private  
    FBits: TArrayOfFloat;  
    function GetValPtr(X, Y: Integer): PFloat;  
    function GetValue(X, Y: Integer): TFloat;  
    procedure SetValue(X, Y: Integer; const Value: TFloat);  
    function GetBits: PArrayOfFloat;  
  protected  
    function GetValueS(X, Y: Integer): TFloat;  
    procedure SetValueS(X, Y: Integer; const Value: TFloat);  
    procedure ChangeSize(var Width, Height: Integer; NewWidth, NewHeight: Integer); override;  
  public  
    destructor Destroy; override;  
    function Empty: Boolean; override;  
    procedure Clear();  
    property ValPtr[X, Y: Integer]: PFloat read GetValPtr;  
    property Value[X, Y: Integer]: TFloat read GetValueS write SetValueS; default;  
    property Values[X, Y: Integer]: TFloat read GetValueS;  
    property Bits: PArrayOfFloat read GetBits;  
  end;  
implementation  
uses  
  GR32_LowLevel;  
{ TFloatMap }  
procedure TFloatMap.ChangeSize(var Width, Height: Integer; NewWidth,  
  NewHeight: Integer);  
begin  
  SetLength(FBits, NewWidth * NewHeight);  
  Width := NewWidth;  
  Height := NewHeight;  
end;  
procedure TFloatMap.Clear();  
begin  
  FillLongword(FBits[0], Width * Height, 0);  
  Changed;  
end;  
destructor TFloatMap.Destroy;  
begin  
  FBits := nil;  
  inherited;  
end;  
function TFloatMap.Empty: Boolean;  
begin  
  Result := not Assigned(FBits);  
end;  
function TFloatMap.GetBits: PArrayOfFloat;  
begin  
  Result := @FBits[0];  
end;  
function TFloatMap.GetValPtr(X, Y: Integer): PFloat;  
begin  
  Result := @FBits[X + Y * Width];  
end;  
function TFloatMap.GetValue(X, Y: Integer): TFloat;  
begin  
  Result := FBits[X + Y * Width];  
end;  
function TFloatMap.GetValueS(X, Y: Integer): TFloat;  
begin  
  if (X >= 0) and (Y >= 0) and  
    (X < Width) and (Y < Height) then  
    Result := GetValue(X, Y)  
  else  
    Result := 0;  
end;  
procedure TFloatMap.SetValue(X, Y: Integer; const Value: TFloat);  
begin  
  FBits[X + Y * Width] := Value;  
end;  
procedure TFloatMap.SetValueS(X, Y: Integer; const Value: TFloat);  
begin  
  if (X >= 0) and (Y >= 0) and  
    (X < Width) and (Y < Height) then  
    SetValue(X, Y, Value)  
end;  
end.
